package com.zyh.service.impl;

import com.zyh.dao.FollowDao;
import com.zyh.dao.UserDao;
import com.zyh.pojo.User;
import com.zyh.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FollowServiceImpl implements FollowService {
    @Autowired
    FollowDao followDao;
    @Autowired
    UserDao userDao;
    /**
     * 判断用户A是否关注了用户B  既A是不是B的粉丝
     * @param userA
     * @param userB
     * @return
     */
    @Override
    public boolean judgeFollow(String userA,String userB) {
        return followDao.judgeFollow(userDao.findByName(userA).getId(),userDao.findByName(userB).getId());
    }

    @Override
    public void follow(String follow, String befollow) {
        followDao.follow(userDao.findByName(follow).getId(),userDao.findByName(befollow).getId());
    }

    @Override
    public void unfollow(String follower, String befollower) {
        followDao.unfollow(userDao.findByName(follower).getId(),userDao.findByName(befollower).getId());
    }

    @Override
    public List<User> followers(String username) {
        return followDao.followers(userDao.findByName(username).getId());
    }

    @Override
    public List<User> followings(String username) {
        return followDao.followings(userDao.findByName(username).getId());
    }
}
